########################
# Uninstaller sections #
########################
!include "AddToPath.nsi"

# C::B core end

Section "Uninstall"
	; Remove registry keys
	DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\CodeBlocks"
	DeleteRegKey HKLM SOFTWARE\CodeBlocks

    DeleteRegKey HKCU "${REGKEY}"


	# IfFileExists $INSTDIR\MinGW\bin 0 +3
	Push $INSTDIR\MinGW\bin
	Call un.RemoveFromPath
	
	RMDir /r $INSTDIR\MinGW
	RMDir /r $INSTDIR\share
	Delete  $INSTDIR\cb_console_runner.exe
	Delete  $INSTDIR\codeblocks.dll
	Delete  $INSTDIR\codeblocks.exe
	Delete  $INSTDIR\codesnippets.exe
	Delete  $INSTDIR\exchndl.dll
	Delete  $INSTDIR\mingwm10.dll
	Delete  $INSTDIR\wxchartctrl.dll
	Delete  $INSTDIR\wxcustombutton.dll
	Delete  $INSTDIR\wxflatnotebook.dll
	Delete  $INSTDIR\wxmsw28u_gcc_cb.dll
	Delete  $INSTDIR\wxscintilla.dll
	Delete  $INSTDIR\wxsmithlib.dll

	RMDir /r ${WX_DESTINATION}
	
	Delete $INSTDIR\Uninstall.exe
	RMDir $INSTDIR
    # If $INSTDIR was already removed, skip these next steps
    IfFileExists $INSTDIR 0 instDirOperated
        # It appears $INSTDIR is not empty, thus it could not be removed.
        # Ask the user to probably force the removal.
        MessageBox MB_YESNO|MB_ICONQUESTION \
            "Remove all files in your Code::Blocks directory?$\r$\n(If you have anything you created that you want to keep, click No.)" \
            /SD IDNO IDYES yesRMDir IDNO noRMDir
yesRMDir:
        # Try to delete all remaining files and finally $INSTDIR recursively
        Delete $INSTDIR\*.*
        RMDir /r $INSTDIR
        IfFileExists $INSTDIR 0 instDirOperated
            MessageBox MB_OK|MB_ICONEXCLAMATION \
                "Warning: $INSTDIR could not be removed.$\r$\n(Probably missing access rights?)" \
                /SD IDOK
noRMDir:
        # If user selected "no" -> skip the next steps
instDirOperated:
    # fall through
	

	RMDir /r $SMPROGRAMS\CodeBlocks
	

SectionEnd
